<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href='./layui/css/layui.css'>
    <script src="./layui/layui.js"></script>
    <style>
        .layui-nav {
            text-align: right;
        }

        .main {
            padding: 20px;
        }
    </style>
</head>
<body>
    <ul class="layui-nav">
        <li class="layui-nav-item userInfo"></li>
    </ul>
    <div class="main">
        <div class="layui-panel">
            <div style="padding: 50px 30px;">

                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>标题</th>
                            <th>发布时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>猪八戒</td>
                            <td>汉族</td>
                        </tr>                    
                    </tbody>
                </table>

            </div>
        </div>
    </div>
    <script src="../js_common/AllFunction.js"></script>
    <script>
        let userInfo = getCookie('userInfo') ? JSON.parse(getCookie('userInfo')) : null;
        if (userInfo) {
            document.querySelector('.userInfo').innerHTML = `${userInfo.mobile} 用户欢迎`
        } else {
            document.querySelector('.userInfo').innerHTML = '<a href="login.html">登录</a>'
        }
        let xhr = new XMLHttpRequest;
        xhr.open('GET', 'http://phpclub.org.cn/edu/server/news.php');
        xhr.send();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                let html = '';
                JSON.parse(xhr.responseText).data.forEach((item) => {
                    html += `<tr>
                        <td><a href='./content.html?id=${item.id}'>${item.title}</a></td>
                        <td>${format(item.created_at)}</td>
                        </tr>`;
                });
                document.querySelector('tbody').innerHTML=html;
                }
            }
    </script>
</body>
</html>